package infiews.util;

import infiews.crawler.Crawler;

import java.io.PrintStream;
import java.sql.SQLException;

public class Logger {

	public void error( String errorMessage ){
		if( isOutput ){
			out.println( "[ERROR]: " + errorMessage );
		}
	}
	
	public void info( String infoMessage ){
		if( isOutput ){
			out.println( "* " + infoMessage );
		}
	}

	public void exception(SQLException e){
		if( isOutput ){
			out.println("[SQL EXCEPTION]");
			out.println("SQLState: " + e.getSQLState());
			out.println("VendorError: " + e.getErrorCode());
			e.printStackTrace(out);
			out.println("[/SQL EXCEPTION]");
		}
	}

    public void exception (Exception e){
		if( isOutput ){
			out.println("[EXCEPTION]");
			e.printStackTrace(out);
			out.println("[/EXCEPTION]");
		}
    }

    private Boolean isOutput = Crawler.getConfig().getBoolean("logging.show_output");
	PrintStream out = System.out;
}
